/*******************************************************************************
 * This file is part of blueprint4j www.blueprint4j.org.
 * 
 *     blueprint4j is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     blueprint4j is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 * 
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with blueprint4j. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package blueprint4j.utils;

public class BindStringSelect extends BindString implements BindStringSelectInterface {

	private VectorString options = null;
	private VectorString results = null;

	public BindStringSelect(String p_name,String p_description,String p_options[],Bindable p_bindable) {
		super(p_name,p_description,p_bindable);
		options = new VectorString(p_options);
	}

	public BindStringSelect(String p_name,String p_description,String p_options[],String p_results[],Bindable p_bindable) {
		super(p_name,p_description,p_bindable);
		options = new VectorString(p_options);
		results = new VectorString(p_results);
	}

	public String get() {
		if (results != null) {
			return options.get(results.indexOf(getSerializable()));
		} else {
			return getSerializable();
		}
	}

	public void set(String value)  {
		if (!options.contains(value)) {
			Log.debug.out("BindStringSelect set to a value ["+value+"] which is not conatined in the options list ["+options+"]","");
		}
		if (results != null) {
			setSerializable(results.get(options.indexOf(value)));
		} else {
			setSerializable(value);
		}
	}

	public void setAsString(String value) {
		set(value);
	}
	
	public String getAsString(){
		return get();
	}
	
	public String[] getOptions() {
		return options.toArray();
	}

	public String[] getDisplays() {
		return getOptions();
	}
	
	public String getDisplay() {
		if (get() != null) {
			return options.get(results.indexOf(get()));
		}
		return null;
	}

	public VectorString getOptionsAsVector() {
		return options;
	}
	
	public void refresh() {}
}

